package com.wlc.exception.demo03;

/**
 * @author 王立朝 wanglichao@champion-credit.com
 * @description 支票账户 具备透支额度
 * @date 2021-07-08 16:34
 */
public class CheckingAccount extends Account {
    /**
     * 透支额度
     */
    double overdraftProtection;

    public CheckingAccount(double overdraftProtection) {
        this.overdraftProtection = overdraftProtection;
    }

    public CheckingAccount(double balance, double overdraftProtection) {
        super(balance);
        this.overdraftProtection = overdraftProtection;
    }

    /**
     * 取钱
     */
    @Override
    void withdraw(double amount) throws OverdraftException {
        // 取钱的金额> 余额 + 透支额度  ：  提示已经超过可透支额度
        if (amount > this.overdraftProtection + this.balance) {
            double deficit = amount - this.balance - this.overdraftProtection;
            throw new OverdraftException("取钱失败！ 已经 超过可透支额度了。。", deficit);
        }
        this.balance -= amount;
    }

}
